const mongoose = require('mongoose');
mongoose.set('useCreateIndex',true)
//数据库开启连接
   const DB_NAME = 'adoption' 
   const DB_URL = 'localhost:27017'

   module.exports = new Promise((resolve,reject) => {
       //连接数据库
       mongoose.connect(`mongodb://${DB_URL}/${DB_NAME}`, { useNewUrlParser: true,useUnifiedTopology: true })

       //监听连接状态
       mongoose.connection.on('open',err => {
           if(!err){
               console.log(`位于${DB_URL}上的${DB_NAME}数据库连接成功了`)
               resolve()
           }else{
               reject(err)
               console.log(err)
           }
       })
   })


 